package com.turnengine.client.local.player.bean;

import com.turnengine.client.local.alliance.enums.AllianceMemberType;
import com.turnengine.client.local.player.enums.PlayerEmailAlerts;
import com.turnengine.client.local.unit.bean.IUnitCount;
import java.util.List;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Player.
 */
public class Player implements IPlayer, Comparable<IPlayer> {

	/** The id. */
	private int id = -1;
	/** The name. */
	private String name = "";
	/** The user id. */
	private int userId = -1;
	/** The faction id. */
	private int factionId = -1;
	/** The request id. */
	private int requestId = -1;
	/** The alliance id. */
	private int allianceId = -1;
	/** The leave turns. */
	private int leaveTurns = -1;
	/** The member type. */
	private AllianceMemberType memberType = AllianceMemberType.NONE;
	/** The email alerts. */
	private PlayerEmailAlerts emailAlerts = PlayerEmailAlerts.ENABLED;
	/** The unit list. */
	private List<IUnitCount> unitList;

	/**
	 * Creates a new Player.
	 */
	public Player() {
	}

	/**
	 * Creates a new Player.
	 * @param id the id
	 * @param name the name
	 * @param userId the user id
	 * @param factionId the faction id
	 * @param requestId the request id
	 * @param allianceId the alliance id
	 * @param leaveTurns the leave turns
	 * @param memberType the member type
	 * @param emailAlerts the email alerts
	 * @param unitList the unit list
	 */
	public Player(int id, String name, int userId, int factionId, int requestId, int allianceId, int leaveTurns, AllianceMemberType memberType, PlayerEmailAlerts emailAlerts, List<IUnitCount> unitList) {
		setId(id);
		setName(name);
		setUserId(userId);
		setFactionId(factionId);
		setRequestId(requestId);
		setAllianceId(allianceId);
		setLeaveTurns(leaveTurns);
		setMemberType(memberType);
		setEmailAlerts(emailAlerts);
		setUnitList(unitList);
	}

	/**
	 * Creates a new Player.
	 * @param player the player
	 */
	public Player(Player player) {
		setId(player.getId());
		setName(player.getName());
		setUserId(player.getUserId());
		setFactionId(player.getFactionId());
		setRequestId(player.getRequestId());
		setAllianceId(player.getAllianceId());
		setLeaveTurns(player.getLeaveTurns());
		setMemberType(player.getMemberType());
		setEmailAlerts(player.getEmailAlerts());
		setUnitList(player.getUnitList());
	}

	/**
	 * Creates a new Player.
	 * @param iPlayer the i player
	 */
	public Player(IPlayer iPlayer) {
		setId(iPlayer.getId());
		setName(iPlayer.getName());
		setUserId(iPlayer.getUserId());
		setFactionId(iPlayer.getFactionId());
		setRequestId(iPlayer.getRequestId());
		setAllianceId(iPlayer.getAllianceId());
		setLeaveTurns(iPlayer.getLeaveTurns());
		setMemberType(iPlayer.getMemberType());
		setEmailAlerts(iPlayer.getEmailAlerts());
		setUnitList(iPlayer.getUnitList());
	}

	/**
	 * Returns the id.
	 * @return the id.
	 */
	public int getId() {
		return id;
	}

	/**
	 * Returns the name.
	 * @return the name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the user id.
	 * @return the user id.
	 */
	public int getUserId() {
		return userId;
	}

	/**
	 * Returns the faction id.
	 * @return the faction id.
	 */
	public int getFactionId() {
		return factionId;
	}

	/**
	 * Returns the request id.
	 * @return the request id.
	 */
	public int getRequestId() {
		return requestId;
	}

	/**
	 * Returns the alliance id.
	 * @return the alliance id.
	 */
	public int getAllianceId() {
		return allianceId;
	}

	/**
	 * Returns the leave turns.
	 * @return the leave turns.
	 */
	public int getLeaveTurns() {
		return leaveTurns;
	}

	/**
	 * Returns the member type.
	 * @return the member type.
	 */
	public AllianceMemberType getMemberType() {
		return memberType;
	}

	/**
	 * Returns the email alerts.
	 * @return the email alerts.
	 */
	public PlayerEmailAlerts getEmailAlerts() {
		return emailAlerts;
	}

	/**
	 * Returns the unit list.
	 * @return the unit list.
	 */
	public List<IUnitCount> getUnitList() {
		return unitList;
	}

	/**
	 * Sets the id.
	 * @param id the id to set.
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sets the name.
	 * @param name the name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Sets the user id.
	 * @param userId the user id to set.
	 */
	public void setUserId(int userId) {
		this.userId = userId;
	}

	/**
	 * Sets the faction id.
	 * @param factionId the faction id to set.
	 */
	public void setFactionId(int factionId) {
		this.factionId = factionId;
	}

	/**
	 * Sets the request id.
	 * @param requestId the request id to set.
	 */
	public void setRequestId(int requestId) {
		this.requestId = requestId;
	}

	/**
	 * Sets the alliance id.
	 * @param allianceId the alliance id to set.
	 */
	public void setAllianceId(int allianceId) {
		this.allianceId = allianceId;
	}

	/**
	 * Sets the leave turns.
	 * @param leaveTurns the leave turns to set.
	 */
	public void setLeaveTurns(int leaveTurns) {
		this.leaveTurns = leaveTurns;
	}

	/**
	 * Sets the member type.
	 * @param memberType the member type to set.
	 */
	public void setMemberType(AllianceMemberType memberType) {
		this.memberType = memberType;
	}

	/**
	 * Sets the email alerts.
	 * @param emailAlerts the email alerts to set.
	 */
	public void setEmailAlerts(PlayerEmailAlerts emailAlerts) {
		this.emailAlerts = emailAlerts;
	}

	/**
	 * Sets the unit list.
	 * @param unitList the unit list to set.
	 */
	public void setUnitList(List<IUnitCount> unitList) {
		this.unitList = unitList;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(881, 37);
		hash.append(id);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof Player) {
			Player compare = (Player) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.id, compare.id);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IPlayer compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.id, compare.getId());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("id", id);
		if (name != null) {
			string.append("name", name);
		}
		string.append("userId", userId);
		string.append("factionId", factionId);
		string.append("requestId", requestId);
		string.append("allianceId", allianceId);
		string.append("leaveTurns", leaveTurns);
		if (memberType != null) {
			string.append("memberType", memberType);
		}
		if (emailAlerts != null) {
			string.append("emailAlerts", emailAlerts);
		}
		if (unitList != null) {
			string.append("unitList", unitList);
		}
		return string.toString();
	}
}
